<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/5/7
  Time: 15:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<jsp:include page="include-head.jsp"></jsp:include>

<script type="text/javascript">
    $(function(){
        // 调用专门的函数初始化分页导航条
        initPagination();
    });

    function initPagination(){
        var maxentries = ${requestScope.pageInfo.total};
        var opts = {
            num_edge_entries: 2,                                //边缘页数
            num_display_entries: 3,                             //主体页数
            current_page:${requestScope.pageInfo.pageNum -1},    //第一次加载页面的时候默认值为1，pagination这个插件是从0开始的，所以使用的时候需要减1
            prev_text: "上一页",
            next_text: "下一页",
            callback: pageSelectCallback,                       //回调函数
            items_per_page:${requestScope.pageInfo.pageSize} //每页显示1项
        };
        // 调用分页导航条对应的jQuery 对象的pagination()方法生成导航条
        $("#Pagination").pagination(maxentries, opts);
    }

    // pageIndex 是用户在页面上点击的页码数值
    function pageSelectCallback(pageIndex,JQuery){
        // pageIndex 是当前页页码的索引，相对于pageNum 来说，pageIndex 比pageNum 小1
        var pageNum = pageIndex + 1;
        //当是转发页面的时候，用的是同一个request对象，不需要在后端model.addAttribute,用jsp的param直接取就行
        // 执行页面跳转也就是实现“翻页”
        window.location.href = "admin/get/page.html?pageNum="+pageNum+"&keyword=${param.keyword}";

        // 取消当前超链接的默认行为
        return false;
    }


</script>

<body>
<jsp:include page="include-nav.jsp"></jsp:include>


<div class="container-fluid">
    <div class="row">
        <jsp:include page="include-sidebar.jsp"></jsp:include>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form action="admin/get/page.html" class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input name="keyword" class="form-control has-success" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询</button>
                    </form>
                    <button type="button" class="btn btn-danger" style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove"></i> 删除</button>
                    <button type="button" class="btn btn-primary" style="float:right;" onclick="window.location.href='admin/add.html'"><i class="glyphicon glyphicon-plus"></i> 新增</button>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr>
                                <th width="30">#</th>
                                <th width="30"><input type="checkbox"></th>
                                <th>账号</th>
                                <th>名称</th>
                                <th>邮箱地址</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${empty pageInfo}">
                                <tr>
                                    <td colspan="6">数据为空！</td>
                                </tr>
                            </c:if>

                            <c:if test="${!empty pageInfo}">
                                <c:forEach items="${requestScope.pageInfo.list}" var="admin" varStatus="myStatus">
                                    <tr>
                                        <td>${myStatus.count}</td>
                                        <td><input type="checkbox"></td>
                                        <td>${admin.loginAcct}</td>
                                        <td>${admin.userName}</td>
                                        <td>${admin.email}</td>
                                        <td>
                                            <a href="assign/to/assign/role/page.html?adminId=${admin.id}&pageNum=${pageInfo.pageNum}&keyword=${param.keyword}" type="button" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></a>
                                            <a href="admin/to/edit/page.html?id=${admin.id}&pageNum=${pageInfo.pageNum}&keyword=${param.keyword}" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></a>
                                            <a href="admin/remove/${admin.id}/${requestScope.pageInfo.pageNum}/${param.keyword}.html" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></a>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:if>

                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="6" align="center">
                                    <div id="Pagination" class="pagination"></div>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


</body>
</html>
